﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tools.Tooling
{
    class AngleTool
    {
        /// <summary>
        /// 将angle转为360内的角度
        /// </summary>
        /// <param name="angle">传入角度</param>
        /// <returns></returns>
        static float AngleConvert(float angle)
        {
            float newAngle;
            if (angle > 360)
            {
                newAngle = angle % 360;
            }
            else if (angle < 0)
            {
                if (angle > -360)
                {
                    newAngle = 360 + angle;
                }
                else
                {
                    newAngle = 360 - (-angle % 360);
                }

            }
            else
            {
                newAngle = angle;
            }
            return newAngle;
        }
        /// <summary>
        /// 将angle转为angleUnit内的角度
        /// </summary>
        /// <param name="angle">传入角度</param>
        /// <param name="angleUnit">角度单位</param>
        /// <returns></returns>
        static float AngleConvert(float angle, float angleUnit)
        {
            float newAngle;
            if (angle > angleUnit)
            {
                newAngle = angle % angleUnit;
            }
            else if (angle < 0)
            {
                if (angle > -angleUnit)
                {
                    newAngle = angleUnit + angle;
                }
                else
                {
                    newAngle = angleUnit - (-angle % angleUnit);
                }
            }
            else
            {
                newAngle = angle;
            }
            return newAngle;
        }
    }
}
